const app = getApp();
let page;
Page({
  goto:app.goto,
  /**
   * 页面的初始数据
   */
  data: {
    nameCommunity: wx.getStorageSync('nameCommunity'),
    idCommunity: wx.getStorageSync('idCommunity'),
    
    mrRoom: {
      nameCommunity: "当前暂无绑定房屋"
    },
    list:"",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    app.api.client_community_getMrRoom({
      token: wx.getStorageSync("token"),
      idCommunity: wx.getStorageSync("idCommunity"),
    }, (res) => {
      if (res.data != undefined) {
        console.log(res.data)

        this.setData({
          mrRoom: res.data
        })

        page = 1;
        app.api.client_repair_getRepairs({
          token: wx.getStorageSync('token'),
          idRoom: this.data.mrRoom.idRoom,
          page: page,
        }, (res) => {
          res.data = this.time_transform_str(res.data);
          this.setData({
            list: res.data
          })
          page++
        })

      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    page = 1;

    app.api.client_repair_getRepairs({
      token: wx.getStorageSync('token'),
      idRoom: this.data.mrRoom.idRoom,
      page: page
    }, (res) => {
      res.data = this.time_transform_str(res.data);
      this.setData({
        list: res.data
      })
      page++;
      wx.stopPullDownRefresh();
    })
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

    app.api.client_repair_getRepairs({
      token: wx.getStorageSync('token'),
      idRoom: this.data.mrRoom.idRoom,
      page: page
    }, (res) => {
      res.data = this.time_transform_str(res.data);
      this.setData({
        list: this.data.list.concat(res.data)
      })
      page++;
    })

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  
  
  time_transform_str: function (list) {
    for(let i in list){
      list[i].createTime = list[i].createTime.replace(/-/g, "/").substring(0, 16);
    }
    return list;
  },

})